﻿define(function (require) {
    require('ezdesk/utility/window-drag');
    var service = require('ezdesk/utility/service');
    var NotificationManager = require('ezdesk/service/notification-manager');

    function setWindowLocation() {
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;

        var pannelTopHeight = $("#login").height();
        var pannelTopWidth = $("#login").width();

        var pannelTop = windowHeight / 2 - pannelTopHeight / 2;
        var pannelLeft = windowWidth / 2 - pannelTopWidth / 2;

        //centering
        $('#login').css({
            "position": "absolute",
            "top": pannelTop,
            "left": pannelLeft
        }).show();
    }


    $(function () {
        $.receiveMessage(function (e) {
            var paramKeyRegex = /\w*(?=\:)/g;
            var key = paramKeyRegex.exec(e.data);
            key = key ? key[0] : e.data;
            var params = e.data.substring(key.length + 1).split('|');

            if (key == 'signout') {
                $.postMessage(e.data, '*', window.frames['i-loginpanel']);

            } else {
                $.postMessage(e.data, '*', parent);
            }
        });

        service.OrganizationInfo(function (e) {
            $('.page-title').html(e.FullName);
        });

        setWindowLocation();

        $('.func-min,.func-close').click(function () {
            $.postMessage('hide', '*', parent);
        });
    });
});
